package cn.saddyfire.pattern.responsibility;

/**
 * @author Dee
 * @date 2024/2/22
 * <p>Description:抽象处理者类
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    //该领导处理的请求天数区间
    private int numStart;
    private int numEnd;
    //声明后继者(上级领导)
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }
    //蛇者上级领导对象
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }
    //各级领导处理请假条的方法
    protected abstract void handleLeave(LeaveRequest request);
    //提交请假条
    public void submit(LeaveRequest request) {
        //该领导进行审批
        this.handleLeave(request);
        //如果该领导处理不了，就交给上级领导处理
        if (this.nextHandler !=null && request.getDays() > this.numEnd) {
            if (this.nextHandler != null) {
                this.nextHandler.submit(request);
            }
        } else {
            System.out.println("流程结束");
        }
    }
}
